package com.zengqingfa.examples.mybatisplus.rest;

import com.zengqingfa.examples.mybatisplus.dto.DynamicColumnInfoDTO;
import com.zengqingfa.examples.mybatisplus.dto.DynamicColumnUpdateDTO;
import com.zengqingfa.examples.mybatisplus.response.Result;
import com.zengqingfa.examples.mybatisplus.service.IDynamicColumnService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 动态列表 前端控制器
 * </p>
 * * @since 2022-11-03
 */
@RestController
@RequestMapping("/dynamicColumn")
@Api(tags = "动态列表管理", value = "动态列表管理")
public class DynamicColumnController {

    @Resource
    private IDynamicColumnService dynamicColumnService;


    @ApiOperation(value = "动态列表查询", notes = "动态列表查询")
    @GetMapping("/query")
    public Result<List<DynamicColumnInfoDTO>> query(@ApiParam(value = "模块：1: 供应商", required = true)
                                                    @RequestParam Integer module, HttpServletRequest request) {
        String userId = request.getHeader("USER_ID");
        if (StringUtils.isBlank(userId)) {
            return Result.fail("缺少用户信息");
        }
        return Result.success(dynamicColumnService.queryDynamicColumn(module, userId));
    }

    @ApiOperation(value = "动态列表更新", notes = "动态列表更新")
    @PutMapping("/update")
    public Result<Boolean> update(@RequestBody DynamicColumnUpdateDTO dto, HttpServletRequest request) {
        String userId = request.getHeader("USER_ID");
        if (StringUtils.isBlank(userId)) {
            return Result.fail("缺少用户信息");
        }
        return Result.success(dynamicColumnService.updateDynamicColumn(dto, userId));
    }
}
